package com.sgzn.sgpay.service.support;

import com.sgzn.sgpay.enums.SgsResponseCode;
import com.sgzn.sgpay.model.response.SgsResultResponse;

import java.io.Serializable;

/**
 * SGS响应工具类
 * @author zhongzhongyong
 * @version Id: SgsResponseUtil.java, v 0.1 2018/4/17 22:52 zhongzhongyong Exp $$
 */
public class SgsResponseUtil<T> implements Serializable{
    private static final long serialVersionUID = 6959104193951830234L;

    public final static SgsResponseUtil INSTANCE = new SgsResponseUtil();
    /**
     * 封装Boolean成功响应
     * @return true
     */
    public SgsResultResponse<T> success(T result){
        SgsResultResponse<T> response = new SgsResultResponse<T>();
        response.setResult(result);
        response.setErrorCode(SgsResponseCode.C200.getResponseCode());
        response.setErrorMsg(SgsResponseCode.C200.getResponseDesc());
        return response;
    }

    /**
     * 参数验证失败
     * @param errorMsg 错误信息
     * @return
     */
    public SgsResultResponse<T> fail(String errorCode,String errorMsg){
        SgsResultResponse<T> response = new SgsResultResponse<T>();
        response.setErrorCode(errorCode);
        response.setErrorMsg(errorMsg);
        response.setResult(null);
        return response;
    }

    /**
     * 参数验证失败
     * @param errorMsg 错误信息
     * @return
     */
    public SgsResultResponse<String> fail(String errorCode,String errorMsg, String result){
        SgsResultResponse<String> response = new SgsResultResponse<>();
        response.setErrorCode(errorCode);
        response.setErrorMsg(errorMsg);
        response.setResult(result);
        return response;
    }
}
